﻿Imports System.Data.OleDb

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim newFileLoc As String = ""
        If FUP_Picture.HasFile Then
            newFileLoc = Request.MapPath("pictures")
            newFileLoc = newFileLoc & "/" & FUP_Picture.FileName
            FUP_Picture.SaveAs(newFileLoc)
        Else
            Return
        End If

        Dim conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("CarsConn").ConnectionString)
        Dim sql As String = "INSERT INTO ClassicCars (ModelName,ModelYear,CC,Make,Condition,Color,Registration,Price,ContactNumber,Picture,InfoUrl,SellerPostcode) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11,@f12)"
        Dim cmd As New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", TB_ModelName.Text)
        cmd.Parameters.AddWithValue("@f2", CInt(TB_ModelYear.Text))
        cmd.Parameters.AddWithValue("@f3", CInt(TB_CC.Text))
        cmd.Parameters.AddWithValue("@f4", TB_Make.Text)
        cmd.Parameters.AddWithValue("@f5", TB_Condition.Text)
        cmd.Parameters.AddWithValue("@f6", TB_Color.Text)
        cmd.Parameters.AddWithValue("@f7", TB_Registration.Text)
        cmd.Parameters.AddWithValue("@f8", CInt(TB_Price.Text))
        cmd.Parameters.AddWithValue("@f9", TB_ContactNum.Text)
        cmd.Parameters.AddWithValue("@f10", "pictures/" & FUP_Picture.FileName)
        cmd.Parameters.AddWithValue("@f11", TB_InfoUrl.Text)
        cmd.Parameters.AddWithValue("@f12", TB_PostCode.Text)
        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("Default.aspx")
    End Sub
End Class